function getLocation() {
	// First we must test to see if GeoLocation is even supported.
	if (navigator.geolocation) {
		
		// Now wee can start the service.
		// navigator.geolocation.startup();
		
			// Check to see if the API is ready.
			// if (!navigator.geolocation.isReady()) {
				// alert("Whoops, your GeoLocation API is not currently ready");
			// }
			
			// Make the call
			// navigator.geolocation.getCurrentPosition(success, fail, options);
			navigator.geolocation.getCurrentPosition(function(position) {
				fillDiv(
					position.coords.latitude, 
					position.coords.longitude,
					position.coords.altitude,	
					position.coords.accuracy,
					position.coords.altitudeAccuracy,
					position.coords.heading,
					position.coords.speed
				);
			});
		
		// Shut it down
		// navigator.geolocation.shutdown();
			
	} else {
		alert("Whoops, it seems like your browser doesn't support GeoLocation.");
		$('#location2').html("Unable to detect");
	}

return;
}

function fillDiv(latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed) {
	
	
	/*
	var e = document.getElementById("location");
		e.innerHTML = "";
		e.innerHTML += "Latitude: " + latitude + "<br />";
		e.innerHTML += "Longitude: " + longitude + "<br />";
		*/ 
		$('[name=lat]').val(latitude);
		$('[name=long]').val(longitude);
		
		//e.innerHTML += "Altitude: " + altitude + "<br />";
		//e.innerHTML += "Accuracy: " + accuracy + "<br />";
		//e.innerHTML += "altitudeAccuracy: " + altitudeAccuracy + "<br />";
		//e.innerHTML += "Heading: " + heading + "<br />";
		//e.innerHTML += "Speed: " + speed;
		/*
		$.ajax({
			  url: url,
			  success: function(data) {
			    $('.result').html(data);
			    alert('Load was performed.');
			  }
			});
		*/
		
		var apiKey = "ABQIAAAA1Kb4h1tNxUp5QKPg18z2vhT3hW7-_cfanIUGdvUNbalm8ZIe4hT-E0yHzCliJKxNBQ1r147vO8Pqiw";
		        // http://maps.google.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false
		var url = 'http://maps.google.com/maps/api/geocode/json?latlng='+latitude + ',' + longitude + '&sensor=false'+"&key="+apiKey + '&callback=?';
		//alert(url);
		/*
		$.getJSON(url,
		  function(data, textStatus){
		     console.log(data);
		  });
		  
		  */
		reverseCode(latitude,longitude);
		
		/*
		$.getJSON(url, function(data) {
			alert("json");
			for (var i = 0; i < data.results.length; i++) {
				  //myAddress[i] = data.results[i].formatted_address;
				  $('.result').html('<p>' + data.results[i].formatted_address + '</p>');
				}  
			});
		*/ 	 
return;
}

// Now call
getLocation();